package cc.plumgo.j2me.utils;

import javax.microedition.lcdui.game.Sprite;

import cc.plumgo.ss.core.Constants;
import cc.plumgo.ss.yo.entity.Bullet;

public class CustomRole extends CustomEntity {
	
	protected int attackHarm;
	protected int attackDis;
	protected Bullet bullet;
	protected int index;
	protected int frameNums[];
	protected int blood;
	protected boolean died;
	public CustomRole(int bulletStates) {
		super();
		bullet = new Bullet(bulletStates);
	}
	public Bullet getBullet() {
		return bullet;
	}

	public int getAttackHarm() {
		return attackHarm;
	}
	
	public int getAttackDis() {
		return attackDis;
	}
	
	public void fire() {
		if (bullet.isFiring()) {
			return;
		}
		int x = posX + sprites[index].getWidth() / 2;
		switch (direct) {
		case DIR_RIGHT:
			x += Constants.BULLET_OFFSET_X;
			break;

		case DIR_LEFT:
			x -= Constants.BULLET_OFFSET_X;
			break;
		}
		int y = posY + sprites[index].getHeight() / 2
				- Constants.BULLET_OFFSET_Y;
		bullet.start(x, y, direct);
	}
	
	public void logic() {
		bullet.logic();
	}
	
	public void initFrameNums() {
		frameNums = new int[totalState];
		for (int i = 0; i < totalState; i++) {
			frameNums[i] = -1;
			sprites[i].setVisible(false);
			sprites[i].setRefPixelPosition(89 / 2, 101 / 2);
		}
		visible = false;
	}

	public void updateFrameNums() {
		sprites[index].setFrame(frameNums[index]);
		sprites[index].setVisible(true);
		visible = true;
		for (int i = 0; i < totalState; i++) {
			if (index == i)
				continue;
			sprites[i].setVisible(false);
			frameNums[i] = -1;
		}
	}
	
	public Sprite getCurrentSprite() {
		return sprites[index];
	}
	
	public boolean isDied() {
		return died;
	}
}
